<template>
 <div>
    <div class="menu">
        <div class="container">
          <div class="logo">
              <a href="">
                <img src="../common/image/logo.png" alt="">
              </a>
          </div>
          <div class="menu-list">
            <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" :router="true">
              <el-menu-item v-for="item in menu" :key="item.value" :index="item.value">{{item.name}}</el-menu-item>
            </el-menu>
          </div>
          <div class="search" @click="searchNews">
            <el-input suffix-icon="el-icon-search" v-model="input" placeholder="请输入内容" ></el-input>
          </div>
          <div class="menu-right">
              <a href="javascript:void(0)" @click="login"><i class="el-icon-edit"></i>写作</a>
          </div>
        </div>
    </div>
    <el-dialog title="用户登录" :visible.sync="dialogFormVisible" :close-on-click-modal="false" :close-on-press-escape="false" width="30%">
      <el-form :model="form">
        <el-form-item label="用户名" :label-width="formLabelWidth">
          <el-input v-model="form.name" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" :label-width="formLabelWidth">
          <el-input type="password" v-model="form.pwd" auto-complete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="checkLogin">确 定</el-button>
      </div>
    </el-dialog>
 </div>
</template>

<script>
export default {
  props: {
    activeIndex: {
      type: String,
      default: '/home'
    }
  },
  name: 'home',
  data () {
    return {
      menu: [
        {
          name: '首页',
          value: '/home'
        },
        {
          name: '专题',
          value: '/course'
        },
        {
          name: 'app下载',
          value: '/appp'
        },
        {
          name: '联系合作',
          value: '/contact'
        }
      ],
      input: '',
      dialogFormVisible: false,
      form: {
        name: '',
        pwd: ''
      },
      formLabelWidth: '80px'
    }
  },
  methods: {
    login () {
      // console.log('1111111111')

      this.dialogFormVisible = true
    },
    checkLogin () {
      this.$store.dispatch('login', {
        data: {
          username: this.form.name,
          password: this.form.pwd
        },
        cb: (res) => {
          if (res.data.stateCode === '200') {
            this.$router.push('/admin')
          }
        }
      })
    },
    searchNews () {
      if (this.input) {
        this.$router.push({
          name: 'search',
          params: {
            name: this.input,
            code: 100
          }
        })
      }
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="stylus">
  .menu
    height:60px
    width: 100%
    background-color: #fff
    border-bottom: 1px solid #f5f5f5
    .container
      width:1200px
      margin: 0px auto
      .logo
        float left
        img
          height 46px
          width auto
          padding-top: 10px
          margin-right: 50px
      .menu-list
        float left
      .search
        float left
        padding-top: 10px
        margin-left: 110px
      .menu-right
        float: right
        line-height: 60px
        a
          margin-right: 20px
</style>

<style>
  .el-menu-demo .el-menu-item{
    font-size: 18px;
  }
</style>
